package com.ngc.mall.common.configure;

import com.qcloud.cos.COS;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicSessionCredentials;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

public class COSConfig {
        /**
         * 阿里云 accessKeyId
         */
        @Value("${cos.secretId}")
        private String accessKeyId;

        /**
         * 阿里云 accessKeySecret
         */
        @Value("${cos.secretKey}")
        private String accessKeySecret;

        /**
         * 阿里云 oss endpoint
         */
        @Value("${aliyun.oss.endpoint}")
        private String endpoint;

        @Bean
        public COS cos(){
            return new COSClient(cred, clientConfig);
        }

    // 1 传入获取到的临时密钥 (tmpSecretId, tmpSecretKey, sessionToken)
    String tmpSecretId = "SECRETID";
    String tmpSecretKey = "SECRETKEY";
    String sessionToken = "TOKEN";
    BasicSessionCredentials cred = new BasicSessionCredentials(tmpSecretId, tmpSecretKey, sessionToken);
    // 2 设置 bucket 的地域
// clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分
    Region region = new Region("COS_REGION"); //COS_REGION 参数：配置成存储桶 bucket 的实际地域，例如 ap-beijing，更多 COS 地域的简称请参见 https://cloud.tencent.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(region);
    // 3 生成 cos 客户端
    COSClient cosClient = new COSClient(cred, clientConfig);


}
